//
//  SEGActivityListCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/8/11.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGActivityListCell.h"
@interface SEGActivityListCell ()

/**
 活动图片
 */
@property (nonatomic, strong)UIImageView *picView;
/**
 标题
 */
@property (nonatomic, strong)UILabel *titleLabel;
/**
 活动时间
 */
@property (nonatomic, strong)UILabel *timeLabel;
/**
 浏览人数
 */
@property (nonatomic, strong)UILabel *readCountLabel;
/**
 参加人数
 */
@property (nonatomic, strong)UILabel *joinCountLabel;
/**
 活动状态
 */
@property (nonatomic, strong)UILabel *statusLabel;
/**
 推荐
 */
@property (nonatomic, strong)UIImageView *recommendImage;
@end

@implementation SEGActivityListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = kColor_W;
    
    _picView = [[UIImageView alloc] init];
    _picView.contentMode = UIViewContentModeScaleAspectFill;
    _picView.clipsToBounds = YES;
    [self.contentView addSubview:_picView];
    CGFloat height = 172.0 * ((LYScreenWidth() - 30) / 345.0);//按图片宽高比计算高度
    [_picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.mas_equalTo(height);
    }];
    
    _recommendImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_label")]];
    [self.contentView addSubview:_recommendImage];
    [_recommendImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_picView);
        make.top.equalTo(_picView).offset(10);
//        make.width.mas_equalTo(43);
//        make.height.mas_equalTo(16);
    }];
    _recommendImage.hidden = YES;
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = kFont_16;
    _titleLabel.textColor = kColor_1;
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_picView);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.top.equalTo(_picView.mas_bottom).offset(9);
    }];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = kFont_13;
    _timeLabel.textColor = kColor_3;
    [self.contentView addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_picView);
        make.top.equalTo(_titleLabel.mas_bottom).offset(8);
    }];
    
    UIImageView *readImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_list_view")]];
    [self.contentView addSubview:readImage];
    [readImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_picView);
        make.top.equalTo(_timeLabel.mas_bottom).offset(9);
    }];
    _readCountLabel = [[UILabel alloc] init];
    _readCountLabel.font = kFont_11;
    _readCountLabel.textColor = kColor_3;
    [self.contentView addSubview:_readCountLabel];
    [_readCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(readImage.mas_right).offset(5);
        make.centerY.equalTo(readImage);
    }];
    
    UIImageView *joinImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_list_participate")]];
    [self.contentView addSubview:joinImage];
    [joinImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_readCountLabel.mas_right).offset(40);
        make.centerY.equalTo(readImage);
    }];
    _joinCountLabel = [[UILabel alloc] init];
    _joinCountLabel.font = kFont_11;
    _joinCountLabel.textColor = kColor_3;
    [self.contentView addSubview:_joinCountLabel];
    [_joinCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(joinImage.mas_right).offset(5);
        make.centerY.equalTo(readImage);
    }];
    
    _statusLabel = [[UILabel alloc] init];
    _statusLabel.font = kFont_10;
    _statusLabel.layer.cornerRadius = 2;
    _statusLabel.layer.masksToBounds = YES;
    _statusLabel.layer.borderWidth = 0.5;
    _statusLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_statusLabel];
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.centerY.equalTo(readImage);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(36);
        make.bottom.equalTo(self.contentView).offset(-15);
    }];
}

- (void)setUpCellWithModel:(SEGActivityListModel *)model
{
    [_picView setImageWithURL:[NSURL URLWithString: model.actPic[0]] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_72_72")]];
    _titleLabel.text = model.actName;
    NSString *startTime = [SEGUtils stringDateByFormatString:@"yyyy.MM.dd" withDate:[NSDate dateWithTimeIntervalSince1970:[model.startTime doubleValue]]];
    NSString *endTime = [SEGUtils stringDateByFormatString:@"yyyy.MM.dd" withDate:[NSDate dateWithTimeIntervalSince1970:[model.endTime doubleValue]]];
    _timeLabel.text = [NSString stringWithFormat:@"活动时间：%@ - %@",startTime,endTime];
    _readCountLabel.text = model.readCount;
    _joinCountLabel.text = model.joinCount;
    [self seg_setStatusLabelWithStatus:model.actStatus];
    //活动推荐状态(1:未推荐,2:已推荐)
    if ([model.isRecommend isEqualToString:@"2"]) {
        _recommendImage.hidden = NO;
    }else {
        _recommendImage.hidden = YES;
    }
}

- (void)seg_setStatusLabelWithStatus:(NSString *)actStatus
{
    SEGActivityStatus status = actStatus.integerValue;
    switch (status) {
        case SEGActivityStatus_NotBegin:
        {
            _statusLabel.layer.borderColor = kColor_3.CGColor;
            _statusLabel.textColor = kColor_3;
            _statusLabel.text = @"未开始";
            break;
        }
        case SEGActivityStatus_Underway:
        {
            _statusLabel.layer.borderColor = kColor_T.CGColor;
            _statusLabel.textColor = kColor_T;
            _statusLabel.text = @"进行中";
            break;
        }
        case SEGActivityStatus_Over:
        {
            _statusLabel.layer.borderColor = kColor_3.CGColor;
            _statusLabel.textColor = kColor_3;
            _statusLabel.text = @"已结束";
            break;
        }
    }
    
}
@end
